luci-app-adblock: optimizations & fixes
authorDirk Brenken <[email protected]>
Fri, 6 Jun 2025 05:03:36 +0000 (07:03 +0200)
committerDirk Brenken <[email protected]>
Fri, 6 Jun 2025 05:04:02 +0000 (07:04 +0200)
* optimized the button handling on the front page
* fixed a minor JS error on the DNS statistics page

Signed-off-by: Dirk Brenken <[email protected]>
applications/luci-app-adblock/htdocs/luci-static/resources/view/adblock/dnsreport.js
applications/luci-app-adblock/htdocs/luci-static/resources/view/adblock/overview.js

index 9ca0797a13e2c0edb1dd099ebd059b89aebeeadc..3f3a5c40ff09c2eb4c2684a38a09ffac3096762e 100644 (file)
@@ -177,6 +177,7 @@ function handleAction(ev) {
                                }, _('Cancel')),
                                ' ',
                                E('button', {
+                                       'id': 'refresh',
                                        'class': 'btn cbi-button-action',
                                        'click': function () {
                                                document.querySelectorAll('.cbi-page-actions button').forEach(function (btn) {
index 45d26cd1979f3d62d464f11d475a220497f5a9d9..044ad9bd76cbd6313ad7f594f510f8e3fdf4aca2 100644 (file)
        button handling
 */
 function handleAction(ev) {
-       if (ev !== 'stop' &&
-               document.getElementById('status') &&
-               document.getElementById('status').textContent.substring(0, 6) === 'paused') {
-               ev = 'resume';
-       }
        if (ev === 'restart' || ev === 'reload') {
-               let map = document.querySelector('.cbi-map');
+               const map = document.querySelector('.cbi-map');
                return dom.callClassMethod(map, 'save')
                        .then(L.bind(ui.changes.apply, ui.changes))
                        .then(function () {
+                               document.querySelectorAll('.cbi-page-actions button').forEach(function (btn) {
+                                       btn.disabled = true;
+                                       btn.blur();
+                               });
                                return fs.exec_direct('/etc/init.d/adblock', [ev]);
                        })
        } else {
+               if (ev !== 'stop') {
+                       document.querySelectorAll('.cbi-page-actions button').forEach(function (btn) {
+                               btn.disabled = true;
+                               btn.blur();
+                       });
+                       if (document.getElementById('status') &&
+                               document.getElementById('status').textContent.substring(0, 6) === 'paused') {
+                               ev = 'resume';
+                       }
+               }
                return fs.exec_direct('/etc/init.d/adblock', [ev]);
        }
 }
@@ -38,7 +47,6 @@ return view.extend({
                        uci.load('adblock')
                ]);
        },
-
        render: function (result) {
                let m, s, o;
 
@@ -50,13 +58,17 @@ return view.extend({
                */
                pollData: poll.add(function () {
                        return L.resolveDefault(fs.read_direct('/var/run/adb_runtime.json'), 'null').then(function (res) {
-                               var status = document.getElementById('status');
+                               const status = document.getElementById('status');
+                               const buttons = document.querySelectorAll('.cbi-page-actions button');
                                try {
                                        var info = JSON.parse(res);
                                } catch (e) {
                                        status.textContent = '-';
                                        poll.stop();
                                        if (status.classList.contains('spinning')) {
+                                               buttons.forEach(function (btn) {
+                                                       btn.disabled = false;
+                                               })
                                                status.classList.remove('spinning');
                                        }
                                        ui.addNotification(null, E('p', _('Unable to parse the runtime information!')), 'error');
@@ -69,6 +81,9 @@ return view.extend({
                                                }
                                        } else {
                                                if (status.classList.contains("spinning")) {
+                                                       buttons.forEach(function (btn) {
+                                                               btn.disabled = false;
+                                                       })
                                                        status.classList.remove("spinning");
                                                        if (document.getElementById('btn_suspend')) {
                                                                if (status.textContent.substring(0, 6) === 'paused') {
@@ -87,6 +102,9 @@ return view.extend({
                                        status.textContent = '-';
                                        poll.stop();
                                        if (status.classList.contains('spinning')) {
+                                               buttons.forEach(function (btn) {
+                                                       btn.disabled = false;
+                                               })
                                                status.classList.remove('spinning');
                                        }
                                }
@@ -548,31 +566,31 @@ return view.extend({
                                E('button', {
                                        'class': 'btn cbi-button cbi-button-negative important',
                                        'style': 'float:none;margin-right:.4em;',
-                                       'click': ui.createHandlerFn(this, function () {
+                                       'click': function () {
                                                return handleAction('stop');
-                                       })
+                                       }
                                }, [_('Stop')]),
                                E('button', {
                                        'class': 'btn cbi-button cbi-button-apply important',
                                        'style': 'float:none;margin-right:.4em;',
                                        'id': 'btn_suspend',
-                                       'click': ui.createHandlerFn(this, function () {
+                                       'click': function () {
                                                return handleAction('suspend');
-                                       })
+                                       }
                                }, [_('Suspend')]),
                                E('button', {
                                        'class': 'btn cbi-button cbi-button-positive important',
                                        'style': 'float:none;margin-right:.4em;',
-                                       'click': ui.createHandlerFn(this, function () {
+                                       'click': function () {
                                                return handleAction('reload');
-                                       })
+                                       }
                                }, [_('Save & Reload')]),
                                E('button', {
                                        'class': 'btn cbi-button cbi-button-positive important',
                                        'style': 'float:none',
-                                       'click': ui.createHandlerFn(this, function () {
+                                       'click': function () {
                                                handleAction('restart');
-                                       })
+                                       }
                                }, [_('Save & Restart')])
                        ])
                });